package com.lc.admin.utils;

import java.io.*;
import java.util.Random;

import com.aliyun.oss.*;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectListing;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;

public class OssJavaSdkQuickStart {
    /** 生成一个唯一的 Bucket 名称 */
//    public static void main(String[] args) throws com.aliyuncs.exceptions.ClientException {
//        // Endpoint以华东1（杭州）为例，填写为https://oss-cn-hangzhou.aliyuncs.com，其它Region请按实际情况填写。
//        String endpoint = "https://oss-cn-chengdu.aliyuncs.com";
//        String bucketName = "zhyl20250828";
//        // 填写Bucket所在地域。以华东1（杭州）为例，Region填写为cn-hangzhou。
//        String region = "cn-chengdu";
//        String endPoint ="oss-cn-chengdu.aliyuncs.com";
//
//        // 从环境变量中获取访问凭证。运行本代码示例之前，请先配置环境变量
////        EnvironmentVariableCredentialsProvider credentialsProvider =
////                CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
//
//        DefaultCredentialProvider defaultCredentialProvider = CredentialsProviderFactory.newDefaultCredentialProvider("LTAI5tHuquMDexKopuPXbYjc", "VYt0Rwd5Czv4N11boTnMtyFtUPHwCm");
//
//        // 创建OSSClient实例。
//        // 当OSSClient实例不再使用时，调用shutdown方法以释放资源。
//        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
//        // 显式声明使用 V4 签名算法
//        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
//        OSS ossClient = OSSClientBuilder.create()
//                .endpoint(endpoint)
//                .credentialsProvider(defaultCredentialProvider)
//                .region(region)
//                .build();
//        try {
//            // 1. 创建存储空间（Bucket）
//            // 2. 上传文件
//            String objectName = "upload222.png";
//            FileInputStream fis = new FileInputStream("C:\\Users\\罗成\\Desktop\\upload1.png");
//            // 上传
//            ossClient.putObject(bucketName, objectName, fis);
//            // 上传结束必须返回图片文件地址，回显需要
//            // https://zhyl20250828.oss-cn-chengdu.aliyuncs.com/upload222.png
//            System.out.println("2. 文件 " + objectName + " 上传成功。");
//            String filePath = "https://" + bucketName +"."+endPoint+"/"+objectName;
//            System.out.println(filePath);
//
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                    + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } catch (Exception ce) {
//            System.out.println("Caught an ClientException, which means the client encountered "
//                    + "a serious internal problem while trying to communicate with OSS, "
//                    + "such as not being able to access the network.");
//            System.out.println("Error Message:" + ce.getMessage());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
//    }
    public static void main(String[] args) {
        Random r = new Random();
        int i = r.nextInt(1000000000);
        System.out.println(i);
    }
}